import math
class Solution(object):
    def pathInZigZagTree(self, label):
        max_d = len(bin(label)[2:])
        if max_d % 2 == 0:
            label = 2 ** max_d - 1 + 2 ** (max_d - 1) - label
        out = [1]
        node = 1
        index = 2
        for i in range(max_d - 2, -1, -1):
            if (label >> i) & 1 == 0:
                node = 2 * node
            else:
                node = 2 * node + 1
            if index % 2 == 0:
                out.append(2 ** index - 1 + 2 ** (index - 1) - node)
            else:
                out.append(node)
            index += 1
        return out






data = Solution()
label = 14
print(data.pathInZigZagTree(label))
